package com.yt.controller;

import com.yt.entity.CommonResult;
import com.yt.entity.Novel;
import com.yt.mapper.NovelMapper;
import com.yt.service.NovelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class NovelController {
    @Resource
    NovelService novelService;
    @Value("${server.port}")
    String port;

    @RequestMapping("/timeout")
    public String feigntimeout(){
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return port;
    }


    @GetMapping("/novel/{aid}")
    public CommonResult<List<Novel>> getNovelsByAid(@PathVariable("aid")Integer aid){
        log.info("收到请求");
        try {
            TimeUnit.SECONDS.sleep(6);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        CommonResult<List<Novel>> result=new CommonResult<>();
        result.setCode(200);
        result.setInfo("根据作者ID返回小说内容,from :"+port);
        result.setT(novelService.getNovelsByAid(aid));
        return result;
    }

}
